{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第五次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer5文件夹下，**谢绝交到master下**\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在11月7日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名 廖明可\n",
    "+ 学号 0165204"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一、贫困户模型\n",
    "+ 创建一个类，包含贫困户的义务教育保障、住房安全、饮水安全、肉蛋奶豆的四个属性\n",
    "+ 包含一个是否贫困的预测，如果四个属性有两个以上没有保障（>2)则输出为贫困户\n",
    "+ 对贫困户，采取相应措施（输入参数）对其进行帮扶，使其脱贫\n",
    "+ 至少生成三个实例\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "住户1:\n",
      "贫困户\n",
      "减免义务教育学杂费\n",
      "修建新住房\n",
      "食物补贴\n",
      "\n",
      "住户2:\n",
      "已脱贫\n",
      "\n",
      "住户3:\n",
      "贫困户\n",
      "减免义务教育学杂费\n",
      "安装自来水\n",
      "食物补贴\n"
     ]
    }
   ],
   "source": [
    "class pinkunhu(object):\n",
    "    def __init__(self,x1,x2,x3,x4):\n",
    "        self.yiwujiaoyubaozhang = x1\n",
    "        self.zhufanganquan = x2\n",
    "        self.yinshuianquan = x3\n",
    "        self.roudannaidou = x4\n",
    "    \n",
    "    def education(self,xuezafei):\n",
    "        if xuezafei >= 1000:\n",
    "            self.yiwujiaoyubaozhang = True\n",
    "        else:\n",
    "            self.yiwujiaoyubaozhang = False\n",
    "    \n",
    "    def house(self,year):\n",
    "        if year >= 10:\n",
    "            self.zhufanganquan = True\n",
    "        else:\n",
    "            self.zhufanganquan = False\n",
    "    \n",
    "    def water(self,wuran):\n",
    "        if wuran < 3:\n",
    "            self.yinshuianquan = True\n",
    "        else:\n",
    "            self.yinshuianquan = False\n",
    "    \n",
    "    def food(self,zhonglei):\n",
    "        if zhonglei > 2:\n",
    "            self.roudannaidou = True\n",
    "        else:\n",
    "            self.roudannaidou = False\n",
    "\n",
    "def yuce(self):\n",
    "    sum = 0\n",
    "    if self.yiwujiaoyubaozhang == False:\n",
    "        sum += 1\n",
    "    if self.zhufanganquan == False:\n",
    "        sum += 1\n",
    "    if self.yinshuianquan == False:\n",
    "        sum += 1\n",
    "    if self.roudannaidou == False:\n",
    "        sum += 1\n",
    "    if sum > 2:\n",
    "        print('贫困户')\n",
    "        if self.yiwujiaoyubaozhang == False:\n",
    "            print('减免义务教育学杂费')\n",
    "        if self.zhufanganquan == False:\n",
    "            print('修建新住房')\n",
    "        if self.yinshuianquan == False:\n",
    "            print('安装自来水')\n",
    "        if self.roudannaidou == False:\n",
    "            print('食物补贴')\n",
    "    else:\n",
    "        print('已脱贫')\n",
    "        \n",
    "zhuhu1 = pinkunhu(object,object,object,object)\n",
    "zhuhu2 = pinkunhu(object,object,object,object)\n",
    "zhuhu3 = pinkunhu(object,object,object,object)\n",
    "\n",
    "zhuhu1.education(xuezafei = 800)\n",
    "zhuhu1.house(year = 9)\n",
    "zhuhu1.water(wuran = 2)\n",
    "zhuhu1.food(zhonglei = 2)\n",
    "print('\\n住户1:')\n",
    "yuce(zhuhu1)\n",
    "\n",
    "zhuhu2.education(xuezafei = 1200)\n",
    "zhuhu2.house(year = 15)\n",
    "zhuhu2.water(wuran = 1.8)\n",
    "zhuhu2.food(zhonglei = 3)\n",
    "print('\\n住户2:')\n",
    "yuce(zhuhu2)\n",
    "\n",
    "zhuhu3.education(xuezafei = 950)\n",
    "zhuhu3.house(year = 12)\n",
    "zhuhu3.water(wuran = 3.2)\n",
    "zhuhu3.food(zhonglei = 2)\n",
    "print('\\n住户3:')\n",
    "yuce(zhuhu3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二: 学生信息\n",
    "+ 创建一个类，包含姓名、分数、睡眠时间三个属性\n",
    "+ 包含一个胖瘦的预测，如果分数>90，且睡眠时间少于6小时，输出“BMI可能偏大”，否则输出“体重正常”\n",
    "+ 为使得标准（90分、6小时）可以调整，标准应设为输入的参数\n",
    "+ 至少生成三个实例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "体重正常\n",
      "BMI可能偏大\n",
      "BMI可能偏大\n"
     ]
    }
   ],
   "source": [
    "class student(object):\n",
    "    def __init__(self,name,score,sleep_hour):\n",
    "        self.name = name\n",
    "        self.score = score\n",
    "        self.sleep_hour = sleep_hour\n",
    "    \n",
    "    def get_grade(self,c1,c2):\n",
    "        if self.score > c1 and self.sleep_hour < c2:\n",
    "            print('BMI可能偏大')\n",
    "        else:\n",
    "            print('体重正常')\n",
    "            \n",
    "stu1 = student('张三',80,7)\n",
    "stu1.get_grade(90,6)\n",
    "\n",
    "stu2 = student('李四',91,5.5)\n",
    "stu2.get_grade(90,6)\n",
    "\n",
    "stu3 = student('王二麻子',90.8,5)\n",
    "stu3.get_grade(90,6)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三：“跑步社”成员类\n",
    "+ 创建一个“跑步社”成员类，以学生信息类为父类\n",
    "+ 添加一个属性为跑步\n",
    "+ 如果跑步时间大于30分钟，如果之前预测为“BMI可能偏大”，则输出为“趋向正常”\n",
    "+ 至少生成三个实例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "体重正常\n",
      "BMI可能偏大\n",
      "趋向正常\n"
     ]
    }
   ],
   "source": [
    "class running_club(student):\n",
    "    def __init__(self,name,score,sleep_hour,run):\n",
    "        super().__init__(name,score,sleep_hour)\n",
    "        self.run = run\n",
    "        \n",
    "    def get_grade(self,c1,c2):\n",
    "        if self.score > c1 and self.sleep_hour < c2:\n",
    "            if self.run > 30:\n",
    "                print('趋向正常')\n",
    "            else:\n",
    "                print('BMI可能偏大')\n",
    "        else:\n",
    "            print('体重正常')\n",
    "            \n",
    "stu1 = running_club('张三',80,7,40)\n",
    "stu1.get_grade(90,6)\n",
    "\n",
    "stu2 = running_club('李四',91,5.5,10)\n",
    "stu2.get_grade(90,6)\n",
    "\n",
    "stu3 = running_club('王二麻子',90.8,5,33)\n",
    "stu3.get_grade(90,6)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
